
typedef struct 
{
    int* arr;
    int front;
    int rear;
    int capacity;

} MyCircularQueue;


MyCircularQueue* myCircularQueueCreate(int k) 
{
    MyCircularQueue* head=(MyCircularQueue*)malloc(sizeof(MyCircularQueue)) ;
  int*mid=(int*)malloc(sizeof(MyCircularQueue)*(k+1));
      head->arr=mid;
      head->front=head->rear=0;
      head->capacity=k;
      return head;
}

bool myCircularQueueIsEmpty(MyCircularQueue* obj) 
{
    return obj->rear==obj->front;
}

bool myCircularQueueIsFull(MyCircularQueue* obj) 
{
    return obj->front==(obj->rear+1)%(obj->capacity+1);
}


bool myCircularQueueEnQueue(MyCircularQueue* obj, int value) 
{
    if(myCircularQueueIsFull(obj)) return false;
    obj->arr[obj->rear]=value;
    obj->rear++;
    obj->rear%=(obj->capacity+1);
    return true;
}

bool myCircularQueueDeQueue(MyCircularQueue* obj) 
{
    if(myCircularQueueIsEmpty(obj)) return false;
    obj->front++;
    obj->front%=(obj->capacity+1);
    return true;
}

int myCircularQueueFront(MyCircularQueue* obj) 
{
    if(myCircularQueueIsEmpty(obj)) return -1;
    return obj->arr[obj->front];
}

int myCircularQueueRear(MyCircularQueue* obj) 
{
     if(myCircularQueueIsEmpty(obj)) return -1;
     int id=obj->rear-1;
      if(id==-1) id=obj->capacity;
      return obj->arr[id];
}


void myCircularQueueFree(MyCircularQueue* obj) 
{
    free(obj->arr);
    obj->arr=NULL;
    free(obj);
    obj=NULL;
}

/**
 * Your MyCircularQueue struct will be instantiated and called as such:
 * MyCircularQueue* obj = myCircularQueueCreate(k);
 * bool param_1 = myCircularQueueEnQueue(obj, value);
 
 * bool param_2 = myCircularQueueDeQueue(obj);
 
 * int param_3 = myCircularQueueFront(obj);
 
 * int param_4 = myCircularQueueRear(obj);
 
 * bool param_5 = myCircularQueueIsEmpty(obj);
 
 * bool param_6 = myCircularQueueIsFull(obj);
 
 * myCircularQueueFree(obj);
*/
